<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/web/index', 'Home\IndexController@index');

Route::group(['prefix' => 'web'], function () {
    Route::get('index', 'Home\IndexController@index');
    Route::get('aboutUs', 'Home\IndexController@aboutUs');
    Route::get('left', 'Home\IndexController@left');
    Route::get('captcha', 'Home\LoginController@captcha');
    Route::get('login', 'Home\LoginController@login');
    Route::get('logout', 'Home\LoginController@logout');
    Route::post('doLogin', 'Home\LoginController@doLogin');
});

Route::group(['prefix' => 'web/article'], function () {
    Route::get('activity', 'Home\ArticleController@activityList');
    Route::get('activityDetail/{id}', 'Home\ArticleController@activityDetail');
    Route::get('technical', 'Home\ArticleController@technical');
    Route::get('article_list', 'Home\ArticleController@article_list');
    Route::get('articleDetail/{id}', 'Home\ArticleController@article_detail');
});

Route::group(['prefix' => 'web/goods'], function () {
    Route::get('list', 'Home\ProductController@goodsList');
    Route::get('detail/{id}', 'Home\ProductController@goodsDetail');
});




Auth::routes();

/** common **/

Route::get('/home', 'HomeController@index');

Route::get('/changeNaviModule/{moduleId}', 'HomeController@changeNaviModule');

Route::get('/toRenderLoginForm', 'Auth\LoginController@toRenderLoginForm');

Route::get('/backstage/api/province/getall', 'Backstage\System\AddressController@getProvinces')->name('province.queryapi.getall');

Route::get('/backstage/api/city/getbyprovince/{provinceId}', 'Backstage\System\AddressController@getCitiesByProvince')->name('city.queryapi.getbyprovince');

Route::get('/backstage/api/district/getbycity/{cityId}', 'Backstage\System\AddressController@getDistrictsByCity')->name('district.queryapi.getbycity');

Route::post('/backstage/api/upload', 'Backstage\System\BaseUploadController@doUpload')->name('backstage.uploader.api');

Route::post('/backstage/api/richeditor/upload', 'Backstage\System\BaseUploadController@doRichEditorUpload')->name('backstage.richeditor.uploader.api');

Route::get('/backstage/common/getcityselector', 'Backstage\Common\SelectorController@getCitySelector')->name('common.city.getselector');




/** end common **/

$routes = \App\Lib\Core\RouteBuilder::buildWebRoutes();
foreach ($routes as $route) {
    if ($route['method'] === \App\Route::$ROUTE_METHOD_ANY) {
        if (!empty($route['slug'])) {
            Route::any($route['route'], $route['action'])->middleware('can:'.$route['code']);
        } else {
            Route::any($route['route'], $route['action'])->name($route['slug'])->middleware('can:'.$route['code']);
        }
    } else if ($route['method'] === \App\Route::$ROUTE_METHOD_GET) {
        if (!empty($route['slug'])) {
            Route::get($route['route'], $route['action'])->middleware('can:'.$route['code']);
        } else {
            Route::get($route['route'], $route['action'])->name($route['slug'])->middleware('can:'.$route['code']);
        }
    } else if ($route['method'] === \App\Route::$ROUTE_METHOD_POST) {
        if (!empty($route['slug'])) {
            Route::post($route['route'], $route['action'])->middleware('can:'.$route['code']);
        } else {
            Route::post($route['route'], $route['action'])->name($route['slug'])->middleware('can:'.$route['code']);
        }
    } else if ($route['method'] === \App\Route::$ROUTE_METHOD_PUT) {
        if (!empty($route['slug'])) {
            Route::put($route['route'], $route['action'])->middleware('can:'.$route['code']);
        } else {
            Route::put($route['route'], $route['action'])->name($route['slug'])->middleware('can:'.$route['code']);
        }
    } else if ($route['method'] === \App\Route::$ROUTE_METHOD_DELETE) {
        if (!empty($route['slug'])) {
            Route::delete($route['route'], $route['action'])->middleware('can:'.$route['code']);
        } else {
            Route::delete($route['route'], $route['action'])->name($route['slug'])->middleware('can:'.$route['code']);
        }
    } else if ($route['method'] === \App\Route::$ROUTE_METHOD_PATCH) {
        if (!empty($route['slug'])) {
            Route::patch($route['route'], $route['action'])->middleware('can:'.$route['code']);
        } else {
            Route::patch($route['route'], $route['action'])->name($route['slug'])->middleware('can:'.$route['code']);
        }
    } else if ($route['method'] === \App\Route::$ROUTE_METHOD_OPTIONS) {
        if (!empty($route['slug'])) {
            Route::options($route['route'], $route['action'])->middleware('can:'.$route['code']);
        } else {
            Route::options($route['route'], $route['action'])->name($route['slug'])->middleware('can:'.$route['code']);
        }
    }
}
